<template>
	<view class="box-detail">
		<view class="item-index-top">
			<view class="box-detail-content-item">
				<view class="row-title"><text class="redss">*</text>跟进负责人</view>
				<view class="row-content">
					<input class="uni-input form-input" v-model="sendData.fuzeren" @click="showSinglePicker(1,index)" name="input" placeholder="请填写跟进负责人" disabled=""/>
				</view>
			</view>
		</view>
		<view class="item-line">
			<view class="item-top-text">跟进人</view>
		</view>
		<view class="box-detail-content" v-if="!sendData.listData.length">
			<view class="box-detail-content-item">
				<view class="row-title">跟进人</view>
				<view class="uni-input form-input">无</view>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">联系方式</view>
				<view class="uni-input form-input">无</view>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">主要职责</view>
				<view class="uni-input form-input">无</view>
			</view>
		</view>
		<view class="box-detail-content" v-else v-for="item,index in sendData.listData" :key="index">
			<view class="box-detail-content-item">
				<view class="row-title">跟进人</view>
				<input class="uni-input form-input" v-model="item.genjinren_value" @click="showSinglePicker(2,index)" name="input" placeholder="请填写跟进人" disabled=""/>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">联系方式</view>
				<input class="uni-input form-input"  v-model="item.lianxifang" name="input" placeholder="请填写联系方式"/>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">主要职责</view>
				<input class="uni-input form-input" v-model="item.zhuyaozhi" name="input" placeholder="请填写主要职责"/>
			</view>
			<view class="delete-item-cont" @click="deleteItemOne(index)"></view>
		</view>
		<view class="add-box-detail-content border-wid" @click="addrenItem()"></view>
		<view class="item-line">
			<view class="item-top-text">下一步工作</view>
		</view>
		<view class="box-detail-content" v-if="!sendData.workData.length">
			<view class="form-item date-pick-style">
				<view class="title">启动时间</view>
				<view class="uni-input form-input">无</view>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">工作内容</view>
				<view class="uni-input form-input">无</view>
			</view>
		</view>
		<view class="box-detail-content" v-for="item,index in sendData.workData" :key="index">
			<view class="form-item date-pick-style">
				<view class="title">启动时间</view>
				<uni-datetime-picker class="form-picker" type="date" :value="item.date" start="2020-6-15" end="2025-6-15" @change="dateChange(index,$event)"></uni-datetime-picker>
			</view>
			<view class="box-detail-content-item">
				<view class="row-title">工作内容</view>
				<textarea class="uni-input textarea-style" v-model="item.content" placeholder="请填写工作内容"></textarea>
			</view>
			<view class="delete-item-work" @click="deleteItemTwo(index)"></view>
		</view>
		<view class="add-box-detail-content border-wid" @click="addworkItem()"></view>
		<view class="box-attach">
			<view class="box-detail-content-item">
				<view class="row-title">备注信息</view>
				<textarea class="uni-input textarea-style-dd"  v-model="sendData.beizhu" placeholder="请填写备注信息"></textarea>
			</view>
		</view>
		<mpvue-picker :themeColor="themeColor" ref="mpvuePicker1" :mode="mode" :deepLength="deepLength" :pickerValueDefault="pickerValueDefault"
		 @onConfirm="onConfirm1" @onCancel="onCancel" :pickerValueArray="pickerValueArray"></mpvue-picker>
		 <mpvue-picker :themeColor="themeColor" ref="mpvuePicker2" :mode="mode" :deepLength="deepLength" :pickerValueDefault="pickerValueDefault"
		  @onConfirm="onConfirm2" @onCancel="onCancel" :pickerValueArray="pickerValueArray"></mpvue-picker>
	</view>
</template>

<script>
	import mpvuePicker from '@/components/mpvue-picker/mpvuePicker.vue';
	export default {
		components: {
		    mpvuePicker
		},
		data(){
			return{
				themeColor: '#007AFF',
				mode: '',
				deepLength: 1,
				pickerValueDefault: [3],
				pickerValueArray:[],
				listDataDeletet:[],
				workDataDeletet:[],
				sendData:{
					fuzeren:'',
					fuzeren_value:'',
					beizhu:'',
					listData:[],
					workData:[],
				},
				activeIndex:0,
				code:'',
				projectId:''
			}
		},
		props: {
			pageData: {
				type: Object,
				default(){
					return {}
				}
			},
			changeListData:{
				type: Object,
				default(){
					return {}
				}
			}
		},
		watch:{
			pageData(){
				this.sendData.fuzeren=this.pageData.genjinren
				this.sendData.fuzeren_value=this.pageData.model.MANAGER
				this.sendData.beizhu=this.pageData.model.TEAM_REMARK
				if(this.pageData.dataGrid['TeamMember_view'].datas.length){
					this.sendData.listData=[]
					this.pageData.dataGrid['TeamMember_view'].datas.map(item=>{
						this.projectId=item.PROJ_ID
						this.sendData.listData.push({
							datakey:item.DATAKEY,
							proid:item.PROJ_ID,
							genjinren:item.MEMBER,//联系人
							genjinren_value:'',
							lianxifang:item.LINK_TEL,//联系方式
							zhuyaozhi:item.WORK,//主要职责
							leixing:0,//操作类型  新增行标记为1，删除行标记为3，修改行不处理保留原值0
						})
						if(this.sendData.listData.length){
							this.sendData.listData.map(item=>{
								if(this.changeListData.renmingList){
									this.changeListData.renmingList.map(ites=>{
										if(item.genjinren===ites.CODE){
											item.genjinren_value=ites.CODE_NAME
											item.leixing=0
										}
									})
								}
							})
						}
					})
				}else{
					this.sendData.listData=[]
				}
				if(this.pageData.dataGrid['TemaWork_view'].datas.length){
					this.sendData.workData=[]
					this.pageData.dataGrid['TemaWork_view'].datas.map(item=>{
						this.sendData.workData.push({
							datakey:item.DATAKEY,
							proid:item.PROJ_ID,
							date:item.PLAN_DATE,//启动时间
							content:item.CONTENT,//工作内容
							leixing:0,//操作类型  新增行标记为1，删除行标记为3，修改行不处理保留原值0
						})
					})
				}else{
					this.sendData.workData=[]
				}
			}
		},
		methods:{
			showSinglePicker(num,index) {
				let dataArry=[]
				this.pickerValueArray=[]
				if(this.changeListData.renmingList){
					dataArry=this.changeListData.renmingList 
				}
				if(num===1){
					this.$refs.mpvuePicker1.show()
				}else{
					this.activeIndex=index
					this.$refs.mpvuePicker2.show()
				}
				dataArry.map(item=>{
					this.pickerValueArray.push(
						{
							label: item.CODE_NAME,
							value: item.CODE
						}
					)
				})
				this.mode = 'selector'
				this.deepLength = 1
				this.pickerValueDefault = [0]
				
			},
			onConfirm1(e) {
				console.log(e)
				this.sendData.fuzeren=e.label
				this.sendData.fuzeren_value=e.value[0]
			},
			onConfirm2(e) {
				console.log(e)
				this.sendData.listData[this.activeIndex].genjinren_value=e.label
				this.sendData.listData[this.activeIndex].genjinren=e.value[0]
			},
			onCancel(e) {
			    console.log(e)
			},
			addrenItem(){
				this.sendData.listData.push({
					datakey: this.getUUID(),
					proid:this.projectId,
					genjinren:'',//联系人
					genjinren_value:'',
					lianxifang:'',//联系方式
					zhuyaozhi:'',//主要职责
					leixing:1,//操作类型  新增行标记为1，删除行标记为3，修改行不处理保留原值0
				})
				console.log(this.sendData.listData,"this.sendData.listDatathis.sendData.listData")
			},
			addworkItem(){
				this.sendData.workData.push({
					datakey: this.getUUID(),
					proid:this.projectId,
					date:'',//启动时间
					content:'',//工作内容
					leixing:1,//操作类型  新增行标记为1，删除行标记为3，修改行不处理保留原值0
				})
				console.log(this.sendData.workData,"this.sendData.listDatathis.sendData.listData")
			},
			dateChange(index,e) {
				this.sendData.workData[index].date=e
			},
			deleteItemOne(index){
				if(index===0&&this.sendData.listData.length===1){
					this.sendData.listData=[]
				}else{
					const sendListData=this.sendData.listData
					if(sendListData[index].leixing===0){
						this.listDataDeletet.push({
							datakey: sendListData[index].datakey,
							proid:sendListData[index].proid,
							genjinren:sendListData[index].genjinren,//联系人
							genjinren_value:sendListData[index].genjinren_value,
							lianxifang:sendListData[index].lianxifang,//联系方式
							zhuyaozhi:sendListData[index].zhuyaozhi,//主要职责
							leixing:3, //操作类型  
						})
						this.sendData.listData.splice(index,1)
					}else if(this.sendData.listData[index].leixing===1){
						this.sendData.listData.splice(index,1)
						
					}
				}
			},
			deleteItemTwo(index){
				if(index===0&&this.sendData.workData.length===1){
					this.sendData.workData=[]
				}else{
					const sendWorkData=this.sendData.workData
					if(sendWorkData[index].leixing===0){
						this.workDataDeletet.push({
							datakey: sendWorkData[index].datakey,
							proid:sendWorkData[index].proid,
							date:sendWorkData[index].date,//启动时间
							content:sendWorkData[index].content,//工作内容
							leixing:3,//操作类型  新增行标记为1，删除行标记为3，修改行不处理保留原值 
						})
						this.sendData.workData.splice(index,1)
					}else if(this.sendData.workData[index].leixing===1){
						this.sendData.workData.splice(index,1)
						
					}
				}
			},
			getUUID() {
			   var s = [];
			   var hexDigits = "0123456789abcdef";
			   for (var i = 0; i < 36; i++) {
			    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
			   }
			   s[14] = "4"; 
			   s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); 
			   s[8] = s[13] = s[18] = s[23] = "";
			
			   var uuid = s.join("");
			   return uuid;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap{
		padding-bottom: 60rpx;
	}
	page{
		padding-bottom: 20rpx;
	}
	.delete-item-cont{
		width:54rpx;
		height: 54rpx;
		background: url(../../../../static/images/icon_del.png);
		background-size:36rpx 36rpx ;
		background-repeat: no-repeat;
		background-position:18rpx 0; 
		position: absolute;
		z-index: 100;
		top: 72rpx;
		right: 0;
	}
	.delete-item-work{
		width:54rpx;
		height: 54rpx;
		background: url(../../../../static/images/icon_del.png);
		background-size:36rpx 36rpx ;
		background-repeat: no-repeat;
		background-position:18rpx 0;
		position: absolute;
		z-index: 100;
		top: 0;
		right: 0;
	}
	.box-detail {
		min-height: 760rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		margin: 20rpx;
		padding: 26rpx 30rpx 50rpx 30rpx;
	}
	.item-line{
		// width: 650rpx;
		height: 40rpx;
		// margin: 20rpx 20rpx 18rpx 20rpx;
		background-color: #0099cc;
		border-radius: 10rpx;
		.item-top-text{
			font-family: AlibabaPuHuiTi-Regular;
			padding-left: 20rpx;
			font-size: 26rpx;
			font-weight: normal;
			line-height: 40rpx;
			letter-spacing: 0px;
			color: #ffffff;
		}
	}
	.item-index-top{
		padding: 0 10rpx;
		// width: 650rpx;
		// height: 40rpx;
		// margin: 20rpx 20rpx 18rpx 20rpx;
		// background-color: #0099cc;
		// border-radius: 10rpx;
		.item-top-text{
			font-family: AlibabaPuHuiTi-Regular;
			padding-left: 20rpx;
			font-size: 24rpx;
			font-weight: normal;
			line-height: 40rpx;
			letter-spacing: 0px;
			color: #ffffff;
		}
	}
	.item-top{
		display: flex;
		justify-content: space-between;
		.setion-left{
			display: flex;
			flex-direction: column;
			.left-text-top{
				font-size: 30rpx;
				font-weight: 600;
				color: #414a5d;
			}
			.left-text-bot{
				margin-top: 22rpx;
				font-size: 26rpx;
				color: #7f7f7f;
			}
		}
		.setion-right{
			display: flex;
			flex-direction: column;
			align-items: flex-end;
			.right-text-top{
				height: 30rpx;
				line-height: 30rpx;
				font-size: 26rpx;
				font-weight: normal;
				color: #9a9a9a;
			}
			.right-text-bot{
				margin-top: 22rpx;
				font-size: 28rpx;
				font-weight: normal;
				color: #999999;
			}
		}
	}
	.box-detail-header {
		display: flex;
		justify-content: space-between;
		margin-bottom: 8rpx;
	
		.name {
			font-size: 30rpx;
			color: #414a5d;
			font-weight: bold;
		}
	
		.date {
			font-size: 26rpx;
			color: #9a9a9a;
		}
	}
	
	.box-net {
		font-size: 26rpx;
		color: #0099cc;
	}
	
	.box-detail-content {
		margin-top: 24rpx;
		padding: 0 10rpx;
		border-bottom: 8rpx solid #e8f0f2;
		position: relative;
		
	}
	// .border {
	// 	;
	// }
	.border-wid{
		border-bottom: 1px solid #e8f0f2;
	}
	.border-none{
		border-bottom:0;
	}
	.box-detail-content-item {
		display: flex;
		flex-direction: row;
		// justify-content: flex-start;
		// justify-content: space-between;
		margin-bottom: 20rpx;
	
		.row-title {
			width: 170rpx;
			font-size: 26rpx;
			color: #414a5d;
			text-align: left;
			flex-shrink: 0;
			margin-right: 10rpx;
	
			&.mag {
				margin-left: 18rpx;
			}
		}
	
		.row-content {
			font-size: 26rpx;
			color: #414a5d;
			word-wrap: break-word;
			word-break: break-all;
			flex: 1;
			text-align: left;
	
			&.mag {
				margin-right: 18rpx;
			}
		}
		
		.content-style{
			display: flex;
			justify-content: flex-end;
			align-items: center;
			image{
				width: 27rpx;
				height: 27rpx;
			}
			.history-name{
				margin-left: 10rpx;
				font-family: AlibabaPuHuiTi-Regular;
				font-size: 24rpx;
				color: #0099cc;
			}
		}
	}
	
	.bar-contact {
		background-color: #0099cc;
		border-radius: 10px;
		height: 40rpx;
		line-height: 40rpx;
		padding-left: 18rpx;
		color: #FFFFFF;
		font-size: 24rpx;
		
	}
	.box-attach{
		margin-top: 20rpx;
		padding: 0 10rpx;
	}
	.box-attach-row {
		display: flex;
		align-items: center;
		padding: 0 18rpx;
		height: 38rpx;
		margin-bottom: 10rpx;
		.box-attach-icon {
			width: 34rpx;
			margin-right: 30rpx;
		}
		.box-attach-name {
			font-size: 26rpx;
			color: #0099cc;
		}
	}
	.fixed-action-bar{
		width: 100%;
		display: flex;
		height: 70rpx;
		align-items: center;
		background: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 999;
		.item{
			width: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
			
		}
		.icon{
			width: 30rpx;
		}
		.btn-box{
			width: 90rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 70rpx;
		}
		.text-edit{
			font-size: 24rpx;
			color: #0099cc;
			line-height: 70rpx;
		}
		.text-delete{
			font-size: 24rpx;
			color: #cc3357;
			line-height: 70rpx;
		}
	}
	
	.uni-input{
		font-size: 26rpx;
		color: #808080;
		// border-bottom:1px solid #dce4e6;
		flex:1;
	}
	
	
	.add-box-detail-content{
		height: 90rpx;
		background-image: url(../../../../static/images/add.png);
		background-repeat: no-repeat;
		background-position: 50% 50%;
		background-size: 160rpx 46rpx;
		
	}
	
	.textarea-style{
		height:118rpx ;
		border-bottom:1px solid #dce4e6;
	}
	.textarea-style-dd{
		height:156rpx ;
	}
	// .form-item{
	// 	display: flex;
	// }
	.form-item{
		display: flex;
		justify-content: flex-start;
		margin-bottom: 30rpx;
	}
	.title{
		width: 170rpx;
		flex-shrink: 0;
		font-size: 26rpx;
		color: #414a5d;
	}
	.date-pick-style{
		justify-content: flex-start;
		align-items: center;
		
		.text-input-hou{
			font-size: 26rpx;
			padding: 0 140rpx 0 20rpx;
		}
	}
</style>
